<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Console\Commands;

use App\Models\AdminAction;
use Illuminate\Console\Command;

class InitRoleActionCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'init:role_actions';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $actions = config('role_actions');
        foreach ($actions as $action) {
            $action['action_name'] = 'App\\Http\\Controllers\\' . $action['action_name'];
            if (AdminAction::query()->where('uuid', $action['uuid'])->exists()) {
                AdminAction::query()->where('uuid', $action['uuid'])->update($action);
            } else {
                AdminAction::query()->create($action);
            }
        }
        return 0;
    }
}
